package Year22_Month03.day01;


import java.util.HashMap;
import java.util.Map;

public class Main5 {
    public static int MoreThanHalfNum_Solution(int [] array) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < array.length; i++) {
            if(!map.containsKey(array[i])){
                map.put(array[i],1);
                continue;
            }
            map.put(array[i], map.get(array[i]) + 1);
            if(map.get(array[i]) > (array.length / 2)){
                return array[i];
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,2,2,2,5,4,2};
        System.out.println(MoreThanHalfNum_Solution(arr));
    }
}
